package com.yq.ylmall.activity.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yq.ylmall.activity.service.ICouponService;
import com.yq.ylmall.dto.activity.CouponFormDto;
import com.yq.ylmall.dto.activity.CouponIssueFormDto;
import com.yq.ylmall.dto.activity.CouponQueryDto;
import com.yq.ylmall.result.Result;
import com.yq.ylmall.vo.activity.CouponPageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 优惠券的规则信息 前端控制器
 * </p>
 *
 * @author cherry
 * @since 2024-06-13
 */
@Api(tags = "优惠卷相关接口")
@RestController
@RequestMapping("/admin/activity/coupons")
@RequiredArgsConstructor
public class CouponController {
    private final ICouponService couponService;
    @ApiOperation("新增优惠卷接口")
    @PostMapping("/saveCoupon")
    public Result<Object> saveCoupon(@RequestBody CouponFormDto couponFormDto){
        couponService.saveCoupon(couponFormDto);
        return Result.ok();
    }

    @ApiOperation("分页查询接口")
    @PostMapping("/page")
    public Result<IPage<CouponPageVO>> selectCouponPage(@RequestBody CouponQueryDto couponQueryDto){
        return Result.ok(couponService.selectCouponPage(couponQueryDto));
    }

    @ApiOperation("发放优惠卷接口")
    @PutMapping("{id}/issue")
    public Result<Object> isCoupon(@PathVariable Long id,
            @RequestBody CouponIssueFormDto couponIssueFormDto){
        couponService.issueCoupon(id,couponIssueFormDto);
        return Result.ok();
    }
}
